#ifndef _APP_AUDIO_H
#define _APP_AUDIO_H

#include <stdint.h>
#include <stdbool.h>

// 定义缺失的类型
typedef enum {
    AUDIO_TYPE_PCM,
    AUDIO_TYPE_SBC,
    AUDIO_TYPE_MP3,
    AUDIO_TYPE_AAC,
    AUDIO_TYPE_CVSD,
    AUDIO_TYPE_MSBC,
    AUDIO_TYPE_LC3,
    AUDIO_TYPE_SBC_V2,
    AUDIO_TYPE_OPUS_V2,
} audio_type_t;

typedef enum {
    AUDIO_HW_TYPE_CODEC,
    AUDIO_HW_TYPE_I2S,
    AUDIO_HW_TYPE_PDM,
    AUDIO_HW_TYPE_SPDIF,
} audio_hw_type_t;

typedef void (*audio_sence_report_encoded_frame)(void *arg, uint8_t *data, uint16_t length);
typedef uint32_t (*audio_scene_decoder_req_raw_cb)(uint8_t *data, uint32_t length);

typedef struct {
    uint8_t   bitpool;
    uint16_t sample_rate;
    uint8_t alloc_method;
} a2dp_sbc_param_t;

typedef struct {
    uint32_t sample_rate;
    uint8_t channels;
    audio_type_t audio_type;
    audio_hw_type_t hw_type;
    uint32_t hw_base_addr;
} audio_scene_param_a2dp_sink_t;

typedef struct {
    audio_type_t audio_type;
    audio_hw_type_t hw_type;
    uint32_t hw_base_addr;
    uint32_t sample_rate;
    audio_sence_report_encoded_frame report_enc_cb;
    void *report_enc_arg;
} audio_scene_param_sco_t;

typedef struct {
    a2dp_sbc_param_t sbc_param;
    uint8_t channels;
    audio_type_t audio_input_type;
    audio_type_t audio_output_type;
    audio_hw_type_t hw_type;
    uint32_t hw_base_addr;
    audio_sence_report_encoded_frame report_enc_cb;
    void *report_enc_arg;
    audio_scene_decoder_req_raw_cb dec_req_raw_cb;
} audio_scene_param_a2dp_source_t;

typedef struct {
    audio_type_t audio_type;
    audio_hw_type_t hw_type;
    uint32_t hw_base_addr;
    audio_scene_decoder_req_raw_cb dec_req_raw_cb;
    void (*report_stopped_cb)(void);
} audio_scene_param_tone_t;

// 前向声明
struct audio_scene_t;
typedef struct audio_scene_t audio_scene_t;

//void app_audio_a2dp_sink_start(audio_type_t audio_type, uint32_t sample_rate);
void app_audio_a2dp_sink_start(audio_type_t audio_type, uint32_t sample_rate);
void app_audio_a2dp_sink_stop(void);
void app_audio_a2dp_sink_play(uint8_t *buffer, uint32_t length);

//void app_audio_sco_start(audio_type_t audio_type, audio_sence_report_encoded_frame report_enc_cb, void *report_enc_arg);
void app_audio_sco_stop(void);
void app_audio_sco_recv(bool valid, uint8_t audio_type, uint8_t *buffer, uint32_t length);

void app_audio_voice_recognize_start(void);
void app_audio_voice_recognize_stop(void);

void app_audio_a2dp_source_start(audio_type_t audio_type, a2dp_sbc_param_t *sbc_param, audio_sence_report_encoded_frame report_enc_cb, void *report_enc_arg);
void app_audio_a2dp_source_stop(void);

void app_audio_tone_play(audio_type_t audio_type, uint8_t *tone_sample, uint32_t tone_len);
void app_audio_tone_stop(void);

// 音频场景相关函数声明
audio_scene_t *audio_scene_create(int scene_type, void *param);
void audio_scene_destroy(audio_scene_t *scene);
bool audio_scene_dac_is_ready(audio_scene_t *scene);
void audio_scene_recv_raw_data(audio_scene_t *scene, bool valid, uint8_t *buffer, uint32_t length);
void audio_scene_add_new_tone(audio_type_t audio_type, audio_scene_decoder_req_raw_cb cb);
void audio_scene_remove_tone(void);

// 常量定义
#define AUDIO_SCENE_TYPE_A2DP_SINK 1
#define AUDIO_SCENE_TYPE_SCO 2
#define AUDIO_SCENE_TYPE_A2DP_SOURCE 3
#define AUDIO_SCENE_TYPE_TONE 4

#endif  // _APP_AUDIO_H
